package exercise7;

public class Exercise12_05 {
    public static void main(String []args) throws IllegalTriangleException {
        Triangle triangle1=new Triangle(3,4,5);
        System.out.println("成功创建三角形1");

        System.out.println("下面将创建不合法的三角形");
        Triangle triangle2=new Triangle(1,2,3);
    }
}

class IllegalTriangleException extends Exception{
    double side1;
    double side2;
    double side3;
    double s;
    public IllegalTriangleException(double side1,double side2,double side3,String s){
        super(s);
        this.side1=side1;
        this.side2=side2;
        this.side3=side3;

    }
}

class Triangle{
    double side1;
    double side2;
    double side3;
    public Triangle(double side1,double side2,double side3) throws IllegalTriangleException {
        this.side1=side1;
        this.side2=side2;
        this.side3=side3;
        if (side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1){
            throw new IllegalTriangleException(side1,side2,side3,"不是三角形");
        }
    }


}